#include "mdp.h"
#define Cellular mdp_field

class Automata {
public:
  int value;
};

Automata Rule(Automata& in1,   
	      Automata& in2,
	      Automata& in3) {
  Automata out;
  out.value=(in1.value+in2.value-in3.value+3) % 3;
  return out;
}

int main(int argc, char** argv) {
  mpi.open_wormholes(argc, argv);

  int t;
  int ndim=1;
  int ntime=100;
  int box[]={100};
  mdp_lattice lattice(ndim,box);
  mdp_site x(lattice);

  Cellular<Automata> ca(lattice,ntime);
 
  forallsites(x)
    ca(x,0).value=(int) 3.0*ca.lattice().random(x).plain();
  ca.update(EVENODD,0);

  for(t=0; t<ntime-1; t++) {
    forallsites(x)
      ca(x,t+1)=Rule(ca(x-0,t),ca(x,t),ca(x+0,t));
    ca.update(EVENODD,t+1);
    x.set(0);
    if(ME==0) cout << t << ", " << ca(x,t+1).value << endl;
  }

  ca.save("ca.dat");

  mpi.close_wormholes();
  return 0;
}
